% To be compiled with pdflatex
% This file is to be included into master file via \input command
% Note that there is no \begin{document} \end{document} brackets!

\newpage
\section{Appendix: \\ Matrix derivatives}
\label{sec:MDerivative}

Derivative of linear matrix functional $$\bm{p}^T \mathcal{F} \bm{z}$$
with respect to matrix $\mathcal{F}$
is computed as follows:
\begin{enumerate}
 \item Write the functional in element-wise form:
   $$ f = \bm{p}^T \mathcal{F} \bm{z} =
      \sum_i \sum_j p_i \mathcal{F}_{ij} z_j. $$
 \item Differentiate with respect to $\mathcal{F}_{ij}$:
    $$ \frac{\partial f}{\partial \mathcal{F}_{ij}} = p_i z_j. $$
 \item Thus $$ \frac{\partial}{\partial \mathcal{F}}
 (\bm{p}^T \mathcal{F} \bm{z}) = \bm{p} \bm{z}^T. $$
\end{enumerate}

Derivative of quadratic matrix functional
$$\bm{z}^T \mathcal{F}^T \mathcal{A} \mathcal{F} \bm{z},$$
where $\mathcal{A}$ is
symmetric real valued matrix, with respect to matrix $\mathcal{F}$ is computed
as follows:
\begin{enumerate}
 \item Write the functional in element-wise form:
		$$ f = \bm{z}^T \mathcal{F}^T \mathcal{AF} \bm{z} =
		\sum_{i=1}^m \sum_{l=1}^n \sum_{j=1}^m \sum_{k=1}^n
		\mathcal{F}_{il} \mathcal{F}_{jk} \mathcal{A}_{ij} z_l z_k. $$
 \item Most conveniently, by writing down the above equation for a case of
 small matrix size, say, 2x2, find by inspection that
		$$ \frac{\partial}{\partial \mathcal{F}}
		(\bm{z}^T \mathcal{F}^T \mathcal{AF} \bm{z}) = 2 \mathcal{AF} \bm{zz}^T. $$
\end{enumerate}

Analogously, the derivatives with respect to vector are:
$$ \frac{\partial}{\partial \bm{z}} ( \mathcal{F} \bm{z} ) = \mathcal{F}, $$
$$
	\frac{\partial}{\partial \bm{z}} \bm{z}^{T} \mathcal{F} \bm{z} =
	2 \bm{z}^{T} \mathcal{F}.
$$
